package com.gt

import org.apache.spark.sql.{SQLContext, SparkSession}
import org.apache.spark.{SparkConf, SparkContext}

object SCUtil {

  def createLocalSc(): SparkContext = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("localApp")
    val sc = new SparkContext(conf)
    sc
  }

  def buildLocalSc(): SparkContext = {
    buildLocalSparkSession.sparkContext
  }

  def buildLocalSparkSession(): SparkSession = {
    val conf = new SparkConf()
      // 替换默认的序列化机制
      .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      // 注册需要使用 kryo 序列化的自定义类
      .registerKryoClasses(Array(classOf[Searcher]))
    val session: SparkSession = SparkSession.builder()
      .master("local[*]")
      .appName("localApp")
      .config(conf)
      .getOrCreate()
    session
  }

  class Searcher(query: String){
  }

}
